<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增评价方法')" />
</head>
<body>
    <form class="layui-form">
        <div class="mainBox">
            <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">报告基本信息id：</label>
                <div class="layui-input-block">
                    <input type="text" name="reportId" placeholder="请输入报告基本信息id" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">课程目标标题：</label>
                <div class="layui-input-block">
                    <input type="text" name="title" placeholder="请输入课程目标标题" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">达成度计算实例：</label>
                <div class="layui-input-block">
                    <input type="text" name="achievementDegree" placeholder="请输入达成度计算实例" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">支撑环节：</label>
                <div class="layui-input-block">
                    <input type="text" name="supportingLink" placeholder="请输入支撑环节" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">分值：</label>
                <div class="layui-input-block">
                    <input type="text" name="score" placeholder="请输入分值" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">学生平均得分 JSON：</label>
                <div class="layui-input-block">
                    <input type="text" name="averageScoreJson" placeholder="请输入学生平均得分 JSON" class="layui-input" />
                </div>
            </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="evaluationMethod-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
</body>
<th:block th:include="include :: footer" />
<script th:inline="javascript">

    layui.use(['form', 'jquery','laydate','dictionary'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        let prefix = "/system/evaluationMethod/"

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
        form.on('submit(evaluationMethod-save)', function (data) {
            for(var key in data.field){
                var type=$(data.form).find("input[name='"+key+"']").attr("type");
                if(type=="checkbox"){
                    var value="";
                    $(data.form).find("input[name='"+key+"']:checked").each(function(){
                        value+=$(this).val()+",";
                    })
                    if(value!=""){
                        value=value.substr(0,value.length-1);
                        data.field[key]=value;
                    }

                }
            }
            $.ajax({
                url: prefix+'save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.layui.table.reload("evaluationMethod-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    });
</script>
</html>